<?php
namespace App\Seeder;
use App\Http\Common\MyUtils;
use App\Models\WyPropertys;
use Illuminate\Support\Facades\DB;

/**
 * 新增物业的一些初始化数据，部门，管理职位等
 * Class AddPropertySeeder
 */
class AddPropertySeeder extends BaseSeeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $propertyId = $this->data['wy_property_id'];
        $property = WyPropertys::where('id',$propertyId)->get()->first();
        $groupId = $property->group_id;
        $projectId = MyUtils::getSessionConfig('PROJECT_ID');
        $departmentId = $this->addDepartments($groupId,$projectId,'后勤部','负责员工住宿、餐饮等工作');
        $this->addPositions($groupId,$projectId,$departmentId,'后勤人员','');
        $departmentId = $this->addDepartments($groupId,$projectId,'工程维修部','负责物业项目公共设备设施的维修养护，负责电梯的养护，负责物业设施的日常维保');
        $this->addPositions($groupId,$projectId,$departmentId,'工程经理','');
        $this->addPositions($groupId,$projectId,$departmentId,'水电维修工','');
        $departmentId = $this->addDepartments($groupId,$projectId,'保洁绿化部','负责物业项目公共区域的卫生保洁工作、垃圾清运工作');
        $this->addPositions($groupId,$projectId,$departmentId,'保洁主管','');
        $this->addPositions($groupId,$projectId,$departmentId,'绿化主管','');
        $this->addPositions($groupId,$projectId,$departmentId,'保洁员','');
        $this->addPositions($groupId,$projectId,$departmentId,'绿化员','');
        $departmentId = $this->addDepartments($groupId,$projectId,'安全保卫部','负责物业项目的秩序维护工作、消防工作，负责中控、消控的值班和管理');
        $this->addPositions($groupId,$projectId,$departmentId,'安保经理','');
        $this->addPositions($groupId,$projectId,$departmentId,'保安队长','');
        $this->addPositions($groupId,$projectId,$departmentId,'保安员','');
        $this->addPositions($groupId,$projectId,$departmentId,'消防专员','');
        $this->addPositions($groupId,$projectId,$departmentId,'监控员','');
        $departmentId = $this->addDepartments($groupId,$projectId,'财务部','负责公司财务管理');
        $this->addPositions($groupId,$projectId,$departmentId,'会计','');
        $this->addPositions($groupId,$projectId,$departmentId,'出纳','');
        $departmentId = $this->addDepartments($groupId,$projectId,'客服服务部','处理日常客户、业主接待、报修、投诉、回访、收费等事宜，新项目初期负责办理业主的入住手续');
        $this->addPositions($groupId,$projectId,$departmentId,'客服','');
        $this->addPositions($groupId,$projectId,$departmentId,'楼管','');
        $departmentId = $this->addDepartments($groupId,$projectId,'办公室','负责公司各项行政事务');
        $this->addPositions($groupId,$projectId,$departmentId,'小区管理员','');
    }

    /**
     * 新增部门 https://www.yuque.com/docs/share/eebe70b3-6ccc-44c7-80c6-db0491726fa1?#
     * @param $groupId
     * @param $projectId
     * @param $name
     * @param $description
     * @return int
     */
    public function addDepartments($groupId,$projectId,$name,$description){
        $departmentId = DB::table('departments')->insertGetId([
            'group_id' => $groupId,
            'name' => $name,
            'description' => $description,
            'project_id' => $projectId,
        ]);
        return $departmentId;
    }

    /**
     * 新增职位
     * @param $groupId
     * @param $projectId
     * @param $departmentId
     * @param $name
     * @param $description
     * @return int
     */
    public function addPositions($groupId,$projectId,$departmentId,$name,$description){
        $positionId = DB::table('positions')->insertGetId([
            'group_id' => $groupId,
            'department_id' => $departmentId,
            'name' => $name,
            'description' => $description,
            'project_id' => $projectId,
        ]);
        return $positionId;
    }
}
